<template>
  <div class="work" @scroll="loading">
    <Loading v-if="this.$store.state.isLoading"></Loading>
    <div class="work_item" v-for="item in Worklist" :key="item.id">
      <div class="tx">
        <img :src="`https://ss.lanqb.com/${item.profile.avatar}`" alt="" />
        <span>{{ item.profile.nickname }}</span>
      </div>
      <p>{{ item.content }}</p>
      <div class="pic">
        <img :src="`https://ss.lanqb.com/${item.works.url}`" alt="" />
      </div>
      <div class="comment">
        <div class="com_top">
          <div class="t_l">
            <img :src="`https://ss.lanqb.com/${item.top_comment.avatar}`" />
            <p>{{ item.top_comment.nickname }}</p>
            <span></span>
          </div>
          <div class="t_r">
            <i></i>
            <span>辅导视频</span>
          </div>
        </div>
        <div class="bottom">
          <span>{{ item.top_comment.content }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Loading from "@/components/Loading.vue";
export default {
  name: "WorkView",
  components: {
    Loading,
  },
  data() {
    return {
      Worklist: [],
      page: 1,
    };
  },
  created() {
    this.$store.commit("setLoading", true);
    this.$http({
      methods: "get",
      url: "/lqb/api/works",
      params: {
        type: 6,
        page: this.page,
      },
    }).then(({ data: { data } }) => {
      // console.log(data);
      this.Worklist = data;
      this.$store.commit("setLoading", false);
    });
  },

  mounted() {},

  methods: {
    loading(e) {
      
      if (e.target.scrollTop + e.target.clientHeight >= e.target.scrollHeight) {
        this.$store.commit("setLoading", true);
        this.page++;
        console.log(this.page);
        this.$http({
          methods: "get",
          url: "/lqb/api/works",
          params: {
            type: 6,
            page: this.page,
          },
        }).then(({ data: { data } }) => {
          // console.log(data);
          this.Worklist = [...this.Worklist, ...data];
          this.$store.commit("setLoading", false);
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.work {
  height: 70vh;
  width: 100vw;
  overflow-y: scroll;
  background-color: white;
  // padding-left: 15px;
  margin: auto;

  > .work_item {
    width: 90vw;
    display: flex;
    flex-direction: column;
    margin: 20px auto;
    justify-content: center;
    .tx {
      width: 90vw;
      height: 35px;
      display: flex;
      > img {
        width: 32px;
        height: 32px;
        border-radius: 50%;
      }
      > span {
        margin-left: 10px;
        font-size: 15px;
        height: 32px;
        line-height: 32px;
      }
    }
    > p {
      margin-top: 5px;
      color: #3f4345;
      width: 90vw;
      font-size: 15px;
      line-height: 22px;
      margin-bottom: 5px;
      box-sizing: border-box;
      word-wrap: break-word;
      word-break: break-all;
      text-align: justify;
      font-family: PingFangSC-Regular, microsoft yahei, arial;
    }
    .pic {
      margin: 10px;
      height: 283px;
      width: 60vw;
      > img {
        width: 100%;
        height: 100%;
      }
    }
    .comment {
      width: 90vw;
      height: 98px;
      background-color: #f7f7f7;
      .com_top {
        margin: 5px auto;
        width: 85vw;
        height: 20px;
        display: flex;
        justify-content: space-between;
        .t_l {
          display: flex;
          justify-content: space-around;
          height: 20px;
          > img {
            width: 20px;
            height: 20px;
            border-radius: 50%;
          }
          > span {
            margin-left: 10px;
            margin-top: 2px;
            width: 54px;
            height: 17px;
            background: url("https://assets-cdn.lanqb.com/m-community/t-tag.png")
              no-repeat;
            background-size: 100% 100%;
          }
        }
        .t_r {
          display: flex;
          justify-content: space-around;
          align-items: center;
          > i {
            width: 16px;
            height: 16px;
            background: url("https://assets-cdn.lanqb.com/m-community/t-video.png")
              no-repeat;
            background-size: 100% 100%;
          }
          span {
            color: #5b6164;
            line-height: 12px;
            font-size: 12px;
          }
        }
      }
      .bottom {
        width: 85vw;
        height: 40px;
        margin: 10px auto;
        > span {
          font-size: 15px;
          line-height: 22px;
          color: #5b6164;
        }
      }
    }
  }
}
</style>
